package cn.iflags.Mall.View;

import cn.iflags.Mall.pojo.Paste;
import cn.iflags.Mall.util.PropertiesUtil;
import cn.iflags.Mall.vo.PasteVo;
import org.springframework.web.servlet.ModelAndView;

/**
 * 描述:
 *
 * @author Vincent Vic
 * create 2020-03-15 10:20
 */


public class PasteView {

    //成功跳转到展示页，需要提供代码paste的key
    public ModelAndView gotoPasteShow(String key){

        ModelAndView mav = new ModelAndView();
        mav.setViewName("goto"); //返回的文件名


        mav.addObject("title","代码贴 码农flag");
        mav.addObject("status",0);
        mav.addObject("url", PropertiesUtil.getProperty("paste.server.http.prefix")+"p/"+ key+".do");
        mav.addObject("detail","您可以将本链接分享给您的朋友");
        mav.addObject("info","分享链接");
        mav.addObject("gotoName","前往代码展示页");

        return mav;
    }

    //遇到错误进行跳转回代码贴
    //需要设置错误信息errorInfo
    public ModelAndView errorPaste(String errorInfo){

        ModelAndView mav = new ModelAndView();
        mav.setViewName("goto"); //返回的文件名
        mav.addObject("title","代码贴 码农flag");
        mav.addObject("status",1);
        mav.addObject("url", PropertiesUtil.getProperty("paste.server.http.prefix"));
        mav.addObject("detail","遇到错误:"+errorInfo);
        mav.addObject("info","返回代码贴");
        mav.addObject("errorInfo",errorInfo);

        return mav;
    }

    //显示数据设置并跳转
    public ModelAndView show(PasteVo pasteVo){

        ModelAndView mav = new ModelAndView();
        mav.setViewName("paste"); //返回的文件名


        mav.addObject("showLine",true);
        mav.addObject("codeTitle",pasteVo.getTitleName());
        mav.addObject("language",pasteVo.getSyntax());
        mav.addObject("describe",pasteVo.getDetail());
        mav.addObject("date",pasteVo.getTime());
        mav.addObject("codeStyle",pasteVo.getStyle());
        mav.addObject("code",pasteVo.getCode());

        return mav;
    }

}